package com.maimao.order.serivce;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maimao.core.exception.MaiMaoDaoException;
import com.maimao.model.order.OrderProcessing;
import com.maimao.order.mapper.OrderProcessingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author MaoLin Wang
 * @date 2021/4/6 4:15 下午
 */
@Service
public class OrderProcessingService {

    @Autowired
    private OrderProcessingMapper orderProcessingMapper;

    public List<OrderProcessing> undoList() {
        List<OrderProcessing> orderProcessingList = orderProcessingMapper.selectUndoList();
        return orderProcessingList;
    }

    @Transactional(rollbackFor = MaiMaoDaoException.class)
    public void deleteBatch(List<Long> removeList) {
        if (ObjectUtil.isEmpty(removeList)) {
            return;
        }
        removeList = removeList.stream().filter(Objects::nonNull).collect(Collectors.toList());
        if (ObjectUtil.isNotEmpty(removeList)) {
            orderProcessingMapper.deleteBatchIds(removeList);
        }
    }

    @Transactional(rollbackFor = MaiMaoDaoException.class)
    public void updateBatch(List<OrderProcessing> list) {
        if (ObjectUtil.isEmpty(list)) {
            return;
        }
        orderProcessingMapper.updateBatch(list);
    }
}
